using Furion.DistributedIDGenerator;
using Newtonsoft.Json;

namespace SB2.Application;

public class DynamicChartRepository : AppSugarRepository<DynamicChart>
{
    public DynamicChartRepository(ISqlSugarClient context) : base(context)
    {

    }
    [UnitOfWork]
    public async Task<DynamicChart> GetNewAsync()
    {
        var chart = new DynamicChart { }.New();
        await base.InsertReturnBigIdentityAsync(chart);
        return chart;
    }
}

[SugarTable("dynamicchart")]
public class DynamicChart : EntityHasUser
{
    [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
    public long DynamicChartID { get; set; }
    [SugarColumn(ColumnDescription = "名称", IsNullable = false)]
    public string name { get; set; }
    [SugarColumn(ColumnDescription = "内容")]
    public string Content { get; set; }
    public DynamicChart New()
    {
        DynamicChartID = BitConverter.ToInt64(IDGen.NextID().ToByteArray());
        this.CreateUserID = long.Parse(App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value);
        name = $"草稿{DynamicChartID}";
        Content = "";
        return this;
    }
}

[SugarTable("dynamicchartdes")]
public class DynamicChartDes
{
    [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
    public long DynamicChartID { get; set; }

    public int ChartStatus { get; set; }
}

public class DynamicChartDto : DynamicChart
{
    public string indexImage { get { return $"/uploads/{DynamicChartID}_index_preview.png"; } }

}